#include"system.h"

void ADC_Init()
{
    PMD1bits.ADCMD     = 0;       //Open ADC Modle
    ADCON1bits.TRIGSEL = 0;       //Signal select
    
    ADCON2bits.ADCS = 6;          //Clock

    ADCON1bits.VCFG  = 0;         //Ref+ Set
    ADCON1bits.VNCFG = 0;         //Ref- Set


    ADCON2bits.ADFM = 1;          //Data format
    ADCON2bits.ACQT = 2;          //Transmit time
    ADCON0bits.ADON  = 1;         //Enable ADC

    PIR1bits.ADIF    = 0;
    PIE1bits.ADIE    = 1;
    IPR1bits.ADIP    = 1;

    ADCON0bits.GO    = 1;
    
}

void ADC_ChSet(uint8_t Channel)
{
    ADCON0bits.CHS = Channel;
}

void ADC_Start()
{
    if(!ADCON0bits.GO)
        ADCON0bits.GO = 1;
}